package cn.pconline.autoclub.entity;

import java.util.Date;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Id;
import org.gelivable.dao.Transient;

/**
 * 车友会焦点图
 *
 * @author chensy
 */
@Entity(tableName = "ac_club_focus_img")
public class ClubFocusImg {

    public static final int EMPTY_SEQ = 9; //空焦点图的seq
    @Id
    @Column(name = "focus_img_id")
    private long focusImgId;//焦点图ID
    @Column(name = "club_id")
    private long clubId;//车友会ID
    @Column(name = "img_url")
    private String imgUrl;//图片地址
    @Column(name = "title")
    private String title;//标题
    @Column(name = "url")
    private String url;//链接
    @Column(name = "seq")
    private int seq;//焦点图顺序
    @Column(name = "update_by")
    private long updateBy;//更新者Id
    @Column(name = "update_at")
    private Date updateAt;//更新时间
    /**
     * 焦点图是否为空
     */
    @Transient(cache = false)
    private boolean blank;

    public long getFocusImgId() {
        return focusImgId;
    }

    public void setFocusImgId(long focusImgId) {
        this.focusImgId = focusImgId;
    }

    public long getClubId() {
        return clubId;
    }

    public void setClubId(long clubId) {
        this.clubId = clubId;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getSeq() {
        return seq;
    }

    public void setSeq(int seq) {
        this.seq = seq;
    }

    public long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(long updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateAt() {
        return updateAt;
    }

    public void setUpdateAt(Date updateAt) {
        this.updateAt = updateAt;
    }

    public boolean isBlank() {
        return blank;
    }

    public void setBlank(boolean blank) {
        this.blank = blank;
    }

    public String converImg(String size) {
        if (StringUtils.isBlank(imgUrl)) {
            return imgUrl;
        }
        if (imgUrl.indexOf("_700x350") != -1) {
            return imgUrl.replace("_700x350", "_" + size);
        }
        if (imgUrl.indexOf("_750x375") != -1) {
            return imgUrl.replace("_750x375", "_" + size);
        }
        return imgUrl.replace(".jpg", "_" + size + ".jpg");
    }

    public String getImgUrl280x140() {
        return converImg("280x140");
    }

    public String getImgUrl520x260() {
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_ws.jpg") != -1) {//默认图片
            return imgUrl;
        }
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_sx.jpg") != -1) {
            return imgUrl;
        }
        return converImg("520x260");
    }

    public String getImgUrl170x85() {
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_sx.jpg") != -1) {//默认图片
            return imgUrl.replace("_sx.jpg", "_sxs.jpg");
        }
        if (imgUrl.indexOf("http://img0.pcauto.com.cn/pcauto/1501/27/5858162_ws.jpg") != -1) {
            return imgUrl.replace("_ws.jpg", "_wss.jpg");
        }
        return converImg("170x85");
    }
}
